package com.dolphin.apipassenger.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test/instance-check")
public class InstanceCheckController {
    @Autowired
    DiscoveryClient discoveryClient;

    @GetMapping("/check")
    public String check() {
        List<String> services = discoveryClient.getServices();
        services.forEach(serviceName -> {
            List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
            instances.forEach(instance -> {
                System.out.println(instance.getServiceId() + ":" + instance.getHost() + ":" + instance.getPort());
//                instance.getMetadata().get("name");
            });
        });
        return "success";
    }
}
